package com.cxm.report.dao;

import com.cxm.report.dao.provider.EfficiencyReportProvider;
import com.cxm.report.model.criteria.ReportFilter;
import com.cxm.report.model.data.EfficiencyReport;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author scl.BlueOcean
 * @version 1.0
 * @date 2018年08月13 16:20
 * @description 效率分析报告Dao
 */
@Mapper
public interface EfficiencyReportDao {

    /**删除指定日期的报表数据*/
    @DeleteProvider(type = EfficiencyReportProvider.class,method = "delete")
    void delete(String date);
    /**插入指定日期的报表数据*/
    @DeleteProvider(type = EfficiencyReportProvider.class,method = "batchInsert")
    void batchInsert(String date);



    /**
     * 日报
     * @param filter
     * @return
     */
    @Select(value = "select diffTimeScope timeScope, orderNum count, report_date reportDate from t_efficiency_report where report_date<=#{end} and report_date>=#{begin} order by reportDate DESC, timeScope ")
    List<EfficiencyReport> selectDayReports(ReportFilter filter);
    @Select(value = "select diffTimeScope timeScope, sum(orderNum) count from t_efficiency_report where report_date<=#{end} and report_date>=#{begin} group by timeScope order by timeScope ")
    List<EfficiencyReport> selectReportsOfScope(ReportFilter filter);

    /**
     * 月报
     * @param filter
     * @return
     */
    @Select(value = "select diffTimeScope timeScope, sum(orderNum) count,DATE_FORMAT(report_date,'%Y-%m') reportDate from t_efficiency_report where report_date<=#{end} and report_date>=#{begin} group by reportDate,timeScope order by reportDate DESC,timeScope")
    List<EfficiencyReport> selectReportsGroupMonth(ReportFilter filter);

    /**
     * 周报
     * @param filter
     * @return
     */
    @Select(value = "select diffTimeScope timeScope, sum(orderNum) count,CONCAT(date_sub(report_date,INTERVAL WEEKDAY(report_date) DAY) ,' To ', date_sub(report_date,INTERVAL WEEKDAY(report_date) - 6 DAY) )reportDate from t_efficiency_report where report_date<=#{end} and report_date>=#{begin} group by reportDate,timeScope order by reportDate DESC,timeScope")
    List<EfficiencyReport> selectReportsGroupWeek(ReportFilter filter);
}
